
export function wps_init(tagID, width, height) {
    var iframe;
    var obj;
    iframe = document.getElementById(tagID);
    var codes = [];
    let isWin = (navigator.platform=="Win32") || (navigator.platform=="Windows");
    if (isWin) {    //windows
        codes.push('<object id=DocFrame1 height=' + height + ' width=' + width + ' ');
        codes.push('data=data:application/x-oleobject;base64,7Kd9juwHQ0OBQYiirbY6XwEABAA7DwMAAgAEAB0AAAADAAQAgICAAAQABAD///8ABQBcAFgAAABLAGkAbgBnAHMAbwBmAHQAIABBAGMAdABpAHYAZQBYACAARABvAGMAdQBtAGUAbgB0ACAARgByAGEAbQBlACAAQwBvAG4AdAByAG8AbAAgADEALgAwAAAA ');
        codes.push('classid=clsid:8E7DA7EC-07EC-4343-8141-88A2ADB63A5F viewastext=VIEWASTEXT></object> ');
    } else {
        codes.push("<object  name='webwps' id='webwps_id' type='application/x-wps' uistyle='ribbon'  width='100%'  height='100%'> <param name='Enabled' value='1' />  </object>");
    }
    iframe.innerHTML = codes.join("");
    obj = document.getElementById("DocFrame1");



    //以下方法二选一
    //添加事件方法1
    var fn = function () {
        obj.OnRequireSave = function() {
            alert("用户请求保存文档");
        }

        obj.OnDocumentOpened = function() {
            alert("文档打开");
        }

        obj.OnDocumentCopy = function() {
            alert("用户复制");
        }


        obj.OnDocumentBeforePrint = function() {
            alert("用户打印");
        }

        obj.OnDocumentBeforeSave = function() {
            alert("用户保存");
        }

    };
    fn();
    //添加事件方法2
    /*if(obj.attachEvent){
        console.log("attachEvent...");
        obj.attachEvent('OnRequireSave', function () {
            alert("用户请求保存文档");
            console.log("OnRequireSave..........222222222.....");
        });
    }else{
        console.error("该版本ie不支持attachEvent事件，请设置<meta http-equiv='X-UA-Compatible' content='IE=10' />");
    }
    */
    return obj;
}
